More problems
[andmenj-acm.git] / 11512 - GATTACA / gattaca.cpp
blob630fcce362d77648a74f0b5e6fbc6ccf43eb8a60
1 /*
2 Problem: G - GATTACA
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Naive
7 */
9 using namespace std;
10 #include <algorithm>
11 #include <iostream>
12 #include <iterator>
13 #include <sstream>
14 #include <fstream>
15 #include <cassert>
16 #include <climits>
17 #include <cstdlib>
18 #include <cstring>
19 #include <string>
20 #include <cstdio>
21 #include <vector>
22 #include <cmath>
23 #include <queue>
24 #include <deque>
25 #include <stack>
26 #include <map>
27 #include <set>
29 #define D(x) cout << #x " is " << x << endl
31 int main(){
32 //freopen("gattaca.in", "r", stdin);
33 int T;
34 cin >> T;
35 while (T--){
36 string s;
37 cin >> s;
38 int n = s.size();
39 bool solved = false;
40 map<string, int> cnt;
41 for (int d=n-1; d>0; --d){
42 cnt.clear();
43 for (int i=0, j; (j = i + d) <= n; ++i){
44 cnt[s.substr(i, d)]++;
45 //cout << s.substr(i, d) << " = " << cnt[s.substr(i, d)] << endl;
47 for (map<string, int>::iterator i = cnt.begin(); i != cnt.end(); ++i){
48 if (i->second > 1){
49 cout << i->first << " " << i->second << endl;
50 solved = true;
51 d = -1; //end outer loop
52 break;
56 if (!solved) cout << "No repetitions found!\n";
58 return 0;